how to remove first and last element from array in javascript